package com.wl.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.wl.entity.Buyerapprove_04;
import com.wl.entity.Check_05;
import com.wl.service.BuyerApprove_04Service;
import com.wl.service.Check_05Service;
import com.wl.util.PageData;

@RestController
public class BuyerApprove_04Controller {
	@Autowired
	private BuyerApprove_04Service bas;
	@Autowired
	private Check_05Service cs;

	/**
	 * 模糊查询加分页
	 * 
	 * @param keywords
	 * @param page
	 * @param pageSize
	 * @return
	 */
	@GetMapping(value = "/BuyerApprove_04")
	public PageData<Buyerapprove_04> listBuyerApprove_04(@RequestParam(defaultValue = "") String keywords,
			@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer pageSize) {
		System.out.println(page + "," + pageSize);
		PageData<Buyerapprove_04> pd = bas.listBuyerapprove_04sByPage(keywords, page, pageSize);
		return pd;
	}

	/**
	 * 添加流程
	 * 
	 * @param buyerapprove_04
	 * @return
	 */
	@PostMapping(value = "/BuyerApporve_04")
	public String insertBuyerApprove_04(@RequestBody Buyerapprove_04 buyerapprove_04) {
		System.out.println(buyerapprove_04);
		int n = bas.insertSelective(buyerapprove_04);
		if (n > 0) {
			return "success";
		} else {
			return "failure";
		}
	}

	/**
	 * 查询所有待办事项分页
	 * 
	 * @param keywords
	 * @param page
	 * @param pageSize
	 * @return
	 */
	@GetMapping(value = "/BuyerApprove_04_wait")
	public PageData<Buyerapprove_04> listBuyerApprove_04_waitByPage(@RequestParam(defaultValue = "") String buyerno,
			@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer pageSize) {
		PageData<Buyerapprove_04> pd = bas.listBuyerApprove_04_waitByPage(buyerno, page, pageSize);
		return pd;
	}

	/**
	 * 查询所有已审批流程分页
	 * 
	 * @param keywords
	 * @param page
	 * @param pageSize
	 * @return
	 */
	@GetMapping(value = "/BuyerApprove_04_approved")
	public PageData<Buyerapprove_04> listBuyerApprove_04_approvedByPage(@RequestParam(defaultValue = "") String buyerno,
			@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer pageSize) {
		PageData<Buyerapprove_04> pd = bas.listBuyerApprove_04_approvedByPage(buyerno, page, pageSize);
		return pd;
	}

	@PostMapping(value = "/BuyerApprove_04_submit")
	public boolean updateByPrimaryKeySelective(@RequestBody Buyerapprove_04 buyerapprove_04, Check_05 check_05) {
		buyerapprove_04.setBuyerstatus(1);
		buyerapprove_04.setApprovedetail("同意");
		int n = bas.updateByPrimaryKeySelective(buyerapprove_04);
		check_05.setFlowid(buyerapprove_04.getFlowid());
		check_05.setApplyno(buyerapprove_04.getApplyno());
		cs.insertSelective(check_05);
		return true;
	}

	@PostMapping(value = "/BuyerApprove_04_return")
	public boolean updateByPrimaryKeySelective2(@RequestBody Buyerapprove_04 buyerapprove_04) {
		buyerapprove_04.setBuyerstatus(2);
		buyerapprove_04.setApprovedetail("不同意");
		int n = bas.updateByPrimaryKeySelective(buyerapprove_04);
		return false;
	}
}
